/*
 * @(#)OgnlObjectPropertyAccessor.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.ognl;

import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

import ognl.ObjectPropertyAccessor;
import ognl.OgnlException;

/**
 * The Class OgnlObjectPropertyAccessor.
 * 
 * @author MiddleWare Platform Development Team
 */
class OgnlObjectPropertyAccessor extends ObjectPropertyAccessor {

	/**
	 * Instantiates a new ognl object property accessor.
	 */
	OgnlObjectPropertyAccessor() {
		super();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Object getProperty(Map context, Object target, Object oname) throws OgnlException {
		Object value = super.getProperty(context, target, oname);

		if (value == null) {
			try {
				value = OgnlCallExecutor.getDefaultInstance(PropertyUtils.getPropertyType(target, (String) oname));
			} catch (Exception e) {
				throw new OgnlException("Failed to get the type of property '" + oname + "' from " + target.getClass(), e);
			}

			setProperty(context, target, oname, value);
		}

		return value;
	}
}
